<template>
  <div>
    <PureTableBar title="测评管理" class="h100">
      <template #buttons>
        <p class="text-red-500 absolute left-[120px] leading-7 text-sm">注：双击查看详情</p>

        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="DetailsUpdate(undefined)">
          添加
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" size="small"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination" max-height="250"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @size-change="handleSizeChange" @current-change="handleCurrentChange" @cell-dblclick="DetailsUpdate">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="DetailsUpdate(row)">
              修改
            </el-button>
            <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)"
              @click="handleDelete(row)">
              删除
            </el-button>
            <!-- <el-popconfirm title="是否确认删除?" @confirm="handleDelete(row)">
              <template #reference>
                <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)">
                  删除
                </el-button>
              </template>
            </el-popconfirm> -->
          </template>
        </pure-table>
      </template>
    </PureTableBar>
    <!-- 添加or修改弹窗 -->
    <el-dialog @close="ClosePanelVisible(UpedateRef)" v-model="UpdateVisible" top="5vh" :title="loadingTitle" width="50%"
      center :close-on-click-modal="false">
      <el-scrollbar height="600px">
        <el-form :inline="true" label-width="100px" :rules="rules" ref="UpedateRef" label-position="left"
          :model="updatefrom">
          <el-form-item label="题型" prop="questionType">
            <el-select class="w-220" placeholder="请选择" filterable clearable v-model="updatefrom.questionType"
              :disabled="isdisabled">
              <el-option v-for="cs in QuestionType" :key="cs.id" :label="cs.title" :value="cs.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="题目" prop="title" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.title" />
          </el-form-item>
          <el-form-item label="选项A" prop="answerA" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.answerA" />
          </el-form-item>
          <el-form-item label="选项B" prop="answerB" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.answerB" />
          </el-form-item>
          <el-form-item label="选项C" prop="answerC" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.answerC" />
          </el-form-item>
          <el-form-item label="选项D" prop="answerD" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.answerD" />
          </el-form-item>
          <el-form-item label="选项E" prop="answerE" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.answerE" />
          </el-form-item>
          <el-form-item label="选项F" prop="answerF" v-if="UpdateVisible">
            <wang-edior :height="200" v-model="updatefrom.answerF" />
          </el-form-item>
          <br>
          <el-form-item label="答案" prop="trueAnswer">
            <el-input type="text" class="w-220" placeholder="请填写答案，多选如：ABCD" oninput="value=value.replace(/[^A-F]/g,'');"
              maxlength="6" show-word-limit v-model="updatefrom.trueAnswer" />
          </el-form-item>
        </el-form>
      </el-scrollbar>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="addEvaluation(UpedateRef)">保存</el-button>
          <el-button @click="ClosePanelVisible(UpedateRef)">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import WangEdior from "@/components/wangEditor/index.vue"
import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import { useEvaluation } from "./hook";
const UpedateRef = ref();
const {
  rules,
  columns,
  loading,
  dataList,
  pagination,
  updatefrom,
  isdisabled,
  UpdateVisible,
  QuestionType,
  loadingTitle,
  handleDelete,
  DetailsUpdate,
  addEvaluation,
  handleSizeChange,
  ClosePanelVisible,
  handleCurrentChange
} = useEvaluation()
</script>

<style scoped lang="scss">
.h100 {
  .pure-table {
    height: calc(100% - 60px);

    :deep(.el-table--fit) {
      height: calc(100% - 60px);
    }
  }
}
</style>
